package pers.qianyu.month_202101.date_20210124;

/**
 * 287. 寻找重复数
 * https://leetcode-cn.com/problems/find-the-duplicate-number/
 *
 * @author mizzle rain
 * @date 2021-01-24 11:57
 */
public class FindDuplicate {
    public int findDuplicate(int[] nums) {
        int left = 1, right = nums.length;
        while (left < right) {
            int mid = left + right >> 1;
            int count = 0;
            for (int num : nums) {
                if (num >= left && num <= mid) count++;
            }
            if (count > mid - left + 1) right = mid;
            else left = mid + 1;
        }
        return left;
    }
}
